<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="../inc/conn.asp"-->
<!--#include file="../inc/md5.asp"-->
<!--#include file="../common/admin.asp"-->
<%
key=request.QueryString("key")
uid=request.QueryString("uid")
order=request.QueryString("order")
shoptype=request.QueryString("shoptype")
mark=request.QueryString("mark")
pay=request.QueryString("pay")
search=request.QueryString("search")

if search="搜索" then
	  if key<>"" then
			sqlsearch=sqlsearch+" and title='"&key&"'"
	  end if
	  if uid<>"" then
			sqlsearch=sqlsearch+" and uid='"&uid&"'"
	  end if
	  if order<>"" then
			sqlsearch=sqlsearch+" and [order]='"&order&"'"
	  end if
	  if shoptype<>"" then
			sqlsearch=sqlsearch+" and sid in(select id from Source where sid in(select sid from Shop where typeid="&shoptype&"))"
	  end if
end if

sqlsearch=sqlsearch+" and mark=5 "

'分页-------------------------------------------------------
set Rs=server.CreateObject("ADODB.RecordSet")
sql="select count(sortid) from (Select ROW_NUMBER() OVER (order by id desc ) as sortid,* From orderdetail) as TempTable where 1=1 "&sqlsearch&""
Pager_Pagesize=10 '每页记录数
Rs.open sql,conn,1,1
Pager_TotalRecord=Rs(0) '总记录数
Rs.close
Pager_PageCount=int((Pager_TotalRecord/Pager_Pagesize)+0.99999) '计算总页数
CurrentPage=Request("page") '当前页
'如果不为数字则直接设置页码为1
if isnumeric(CurrentPage)=False Or CurrentPage="" then
	CurrentPage=1
'如果当前页数大于总页数，则直接设置页码为1
elseif  Clng(CurrentPage)>Pager_PageCount then
	CurrentPage=1
end if
Fieldsname=" [Id],[Order],[Uid],[Sid],[Title],[url],pid,[weight],Location,[StoragedTime],[Price],[transCost],[buyqty],[Qty],[Content],[mark],[Type],[Prepaid],[BidsPrice],[EndTime],[Addtime],sortid"
orderBy=" Order by sortid asc"
'拆分SQL语句，必须是select开头，有唯一标识的列
if instr("select",sql)<>-1 then
	if CurrentPage = 1 then
		sql = replace(sql,"select count(sortid)"," select  top " & Pager_Pagesize  & Fieldsname)
	else  
		sql = replace(sql,"select count(sortid)"," select  top " & Pager_Pagesize   & Fieldsname) & " and sortid >(select max(sortid) from (" & replace(sql,"select count(sortid)"," select  top " & Pager_Pagesize * (CurrentPage - 1)  & Fieldsname) & orderBy & ") AA)"
	end if
end if
sql = sql & orderBy
Rs.open sql,conn,1,1
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>main</title>
<link href="../css/style.css" rel="stylesheet" type="text/css"/>
</head>

<body>
<div class="main">
  <div class="main-title">查看</div>
  <div class="main-content">
  <table width="100%" border="0" cellspacing="1" cellpadding="3" class="tab">
  <tr>
    <td colspan="6" align="center">
    <form name="form" method="get" action="">
    商品名<input name="key" type="text" id="key" value="<%=key%>" maxlength="50" />
     订单号<input name="order" type="text" id="order" value="<%=order%>" maxlength="50" />
      买家编号<input name="uid" type="text" id="uid" value="<%=uid%>" maxlength="50" />
      购物来源 <input name="shoptype" type="radio" id="shoptype" value="" />全部
      <input name="shoptype" type="radio" id="shoptype" value="0" <%if shoptype="0" then response.Write " checked"%> />实体店
      <input name="shoptype" type="radio" id="shoptype" value="1" <%if shoptype="1" then response.Write " checked"%>/>购物网
    <input name="mark" type="hidden" value="<%=request.QueryString("mark")%>" />
    <input type="submit" name="search" value="搜索" />
    </form>
    </td>
    </tr>
    </table>
  <table width="100%" border="0" cellspacing="1" cellpadding="3" class="tab">
  <form action="" method="post">
  <tr>
    <td align="center" bgcolor="#FFFFFF"><strong>选择</strong></td>
    <td align="center" bgcolor="#FFFFFF"><strong><span class="items">订单号</span></strong></td>
    <td align="center" bgcolor="#FFFFFF">会员ID</td>
    <td align="center" bgcolor="#FFFFFF">商品</td>
    <td align="center" bgcolor="#FFFFFF">来源</td>
    <td align="center" bgcolor="#FFFFFF">备注</td>
    <td align="center" bgcolor="#FFFFFF">库位</td>
    <td align="center" bgcolor="#FFFFFF">重量(克)</td>
    <td align="center" bgcolor="#FFFFFF">单价</td>
    <td align="center" bgcolor="#FFFFFF">购买数量</td>
    </tr>
    <%do while not Rs.eof
	
	                   set rsSource=conn.execute("select * from Source where id="&Rs("sid")&"") '来源
					   set rsShop=conn.execute("select * from Shop where sid="&rs("sid")&"") '店铺
					   set rsproduct=conn.execute("select * from product where pid="&rs("pid")&"") '产品
					   set rsrate=conn.execute("select rate from orderlist where [order]='"&rs("order")&"'") '读取汇率
	%>
  <tr>
    <td align="center" bgcolor="#FFFFFF"><input type="checkbox" name="checkbox" id="checkbox" value="<%=rs("id")%>" <%if request.QueryString("mark")="4" and rs("Weight")="0" then response.Write " disabled"%> />
      <input type="hidden" name="wid" value="<%=rs("id")%>" /></td>
    <td align="center" bgcolor="#FFFFFF"><%=rs("order")%></td>
    <td align="center" bgcolor="#FFFFFF"><%=rs("uid")%></td>
    <td align="center" bgcolor="#FFFFFF">
    <a target="_blank" href="/shopping/<%=rsproduct("pid")%>.html"><%=rs("title")%><br />
    <img src="<%=rsproduct("pic")%>" height="50">
    </a>
    </td>
    <td align="center" bgcolor="#FFFFFF">
	
	
	<%if rsShop("typeid")="0" then response.Write "实体店" else response.Write "购物网"%>-<%=rsShop("address")%>-<%=rsShop("title")%></td>
    <td align="center" bgcolor="#FFFFFF" title="<%=rs("content")%>"><%=left(rs("content"),30)%></td>
    <td align="center" bgcolor="#FFFFFF"><%=rs("Location")%></td>
    <td align="center" bgcolor="#FFFFFF"><%=rs("weight")%></td>
    <td align="center" bgcolor="#FFFFFF"><%=formatNumber(rs("price"),2,-1)%>日元</td>
    <td align="center" bgcolor="#FFFFFF"><%=rs("Qty")%></td>
    </tr>
    <%
	
	                   set rsrate=nothing
					   set rsproduct=nothing
					   set rsShop=nothing
					   set rsSource=nothing
	Rs.movenext
	loop
	Rs.close
	Set Rs=nothing
	%>
    <tr>
      <td colspan="10" align="center" bgcolor="#FFFFFF" class="page">
              <input type="submit" name="button" value="取消入库">
            
            
            <%
			'select case request.QueryString("mark")
'	  case 0: response.Write "交易失败的商品"
'	  case 1: response.Write "等待审核的商品  <input type=""submit"" name=""button"" value=""有问题的商品""><input type=""submit"" name=""button"" value=""等待购买商品"">"
'	  case 2: response.Write "有问题的商品   <input type=""submit"" name=""button"" value=""交易失败的商品""><input type=""submit"" name=""button"" value=""等待购买商品"">"
'	  case 3: response.Write "等待购买商品     <input type=""submit"" name=""button"" value=""交易失败的商品""><input type=""submit"" name=""button"" value=""等待卖家发货商品"">"
'	  case 4: response.Write "等待卖家发货商品   <input type=""submit"" name=""button"" value=""保存商品重量""><input type=""submit"" name=""button"" value=""已入库的商品"">"
'	  case 5: response.Write "已入库的商品   <input type=""submit"" name=""button"" value=""已创建包裹的商品"">"
'	  case 6: response.Write "已创建包裹的商品   <input type=""submit"" name=""button"" value=""日本已寄出商品商品"">"
'	  case 7: response.Write "日本已寄出商品商品   <input type=""submit"" name=""button"" value=""已签收的商品"">"
'	  case 8: response.Write "已签收的商品"
'	  end select
	  %>
            
            
      </td>
    </tr>
    </form>
    <tr>
    <td colspan="10" align="center" bgcolor="#FFFFFF" class="page">　
      <%
	siteurl=request.servervariables("document_name")
	%>
    <form action="<%=siteurl%>" method="get">
    共 <%=Pager_TotalRecord%> 条 第<%=CurrentPage%>页 / 共 <%=Pager_PageCount%> 页
		<%
		pageurl="key="&key&"&uid="&uid&"&order="&order&"&shoptype="&shoptype&"&pay="&pay&"&mark="&mark&"&search="&search&"&"
		if CurrentPage=1 then
			response.Write(" 首页 ")
			response.Write(" 上一页 ")
		else
			response.Write(" <a href='"&siteurl&"?"&pageurl&"page=1'>首页</a> ")
			response.Write(" <a href='"&siteurl&"?"&pageurl&"page="& (CurrentPage-1) &"'>上一页</a> ")
		end if
		%>
		<%
		if Clng(CurrentPage)=Clng(Pager_PageCount) then
			response.Write(" 下一页 ")
			response.Write(" 尾页 ")
		else
			response.Write(" <a href='"&siteurl&"?"&pageurl&"page="& (CurrentPage+1) &"'>下一页</a> ")
			response.Write(" <a href='"&siteurl&"?"&pageurl&"page="& Pager_PageCount &"'>尾页</a> ")
		end if
		%>
		&nbsp;
		<input name="page" type="text" value="<%=CurrentPage%>" size="1" maxlength="10" />
        <input type="submit" name="button" value="跳转" />
        <input type="hidden" name="key" value="<%=key%>" />
        <input type="hidden" name="uid" value="<%=uid%>" />
        <input type="hidden" name="order" value="<%=order%>" />
        <input type="hidden" name="shoptype" value="<%=shoptype%>" />
        <input type="hidden" name="mark" value="<%=request.QueryString("mark")%>" />
        <input type="hidden" name="pay" value="<%=pay%>" />
        <input type="hidden" name="search" value="搜索" />
        </form>
      </td>
    </tr>
  </table>
</div>
</div>
</body>
</html>
<%


'使用库存
if request.QueryString("oid")<>"" then
  if cdbl(request.QueryString("inventory"))>=(cdbl(request.QueryString("qty"))-cdbl(request.QueryString("buyqty"))) then
  conn.execute("update product set inventory=inventory-"&(cdbl(request.QueryString("qty"))-cdbl(request.QueryString("buyqty")))&" where pid="&request.QueryString("pid")&"")
  conn.execute("update orderdetail set buyqty=buyqty+"&(cdbl(request.QueryString("qty"))-cdbl(request.QueryString("buyqty")))&",mark=4 where id="&request.QueryString("oid")&"")
  else
     conn.execute("update product set inventory=0 where pid="&request.QueryString("pid")&"")
     conn.execute("update orderdetail set buyqty=buyqty+"&cdbl(request.QueryString("inventory"))&" where id="&request.QueryString("oid")&"")
  end if
  response.Redirect "Warehousing.asp"
end if


'缺货退款
if request.QueryString("t")<>"" then
  '增加会员产品交易失败金额
  conn.execute("update [user] set money=money+"&(cdbl(request.QueryString("price"))*cdbl(request.QueryString("Qty")))*cdbl(request.QueryString("rate"))&" where uid = '"&request.QueryString("uid")&"'")
  
  '增加产品交易失败金额明细
  set rss=conn.execute("select money from [user] where uid='"&request.QueryString("uid")&"'")
    Balance=rss("money")
  set rss=nothing
  set rsx=server.createobject("adodb.recordset")
  sql="select * from Funds"
  rsx.open sql,conn,1,3
  rsx.addnew
  rsx("Uid")=request.QueryString("uid")
  rsx("money")=(cdbl(request.QueryString("price"))*cdbl(request.QueryString("Qty")))*cdbl(request.QueryString("rate"))
  rsx("Balance")=Balance
  rsx("content")=request.cookies("admin")("name")&"操作"
  rsx("Type")=3
  rsx("PayType")=2
  rsx("mark")=1
  rsx.update
  rsx.close
  set rsx=nothing
  
  conn.execute("update orderdetail set mark=0 where id ="&request.QueryString("t")&"")
  
  response.Redirect "Warehousing.asp"
end if






wid=request.Form("wid")
if wid<>"" then
   if request.Form("button")="保存商品重量" then
     wid=split(replace(wid," ",""),",")
     for i=0 to ubound(wid)
	 conn.execute("update orderdetail set Weight='"&request.Form("Weight"&wid(i))&"' where id = "&wid(i)&"")
	 next
	 response.Redirect "Warehousing.asp?mark="&request("mark")&"&page="&request.QueryString("page")&""
   end if
end if


checkbox=request.Form("checkbox")
if checkbox<>"" then

	if request.Form("button")="交易失败的商品" then
	
	    moneyuser=split(replace(checkbox," ",""),",")
        for f=0 to ubound(moneyuser)
		   set rss=conn.execute("select * from orderdetail where id="&moneyuser(f)&"")
		   if not rss.eof then
		       set rss2=conn.execute("select * from orderlist where [order]='"&rss("order")&"'")
			   if not rss2.eof then
	              '增加会员产品交易失败金额
			      conn.execute("update [user] set money=money+"&(cdbl(rss("price"))*cdbl(rss("Qty")))*cdbl(rss2("rate"))&" where id = "&rss("uid")&"")
			      '增加产品交易失败金额明细
			      set rsx=server.createobject("adodb.recordset")
				  sql="select * from Funds"
				  rsx.open sql,conn,1,3
				  rsx.addnew
				  rsx("money")=(cdbl(rss("price"))*cdbl(rss("Qty")))*cdbl(rss2("rate"))
				  rsx("user")=rss("uid")
				  rsx("order")=rss("order")
				  rsx("content")="商品交易失败"&rss("title")
				  rsx("paytype")="系统返款"
				  rsx("paymark")=1
				  rsx.update
				  rsx.close
				  set rsx=nothing
			   set rss2=nothing
			   end if
		   set rss=nothing
		   end if  
		next
		conn.execute("update orderdetail set mark=0 where id in ("&checkbox&")")

	elseif request.Form("button")="等待审核的商品" then
		conn.execute("update orderdetail set mark=1 where id in ("&checkbox&")")
	
	elseif request.Form("button")="取消入库" then
		conn.execute("update orderdetail set mark=4 where id in ("&checkbox&")")
	
	elseif request.Form("button")="有问题的商品" then
		conn.execute("update orderdetail set mark=2 where id in ("&checkbox&")")
	
	elseif request.Form("button")="等待购买商品" then
		conn.execute("update orderdetail set mark=3 where id in ("&checkbox&")")
		
	elseif request.Form("button")="等待卖家发货商品" then
		conn.execute("update orderdetail set mark=4 where id in ("&checkbox&")")
		
	elseif request.Form("button")="已入库的商品" then
		conn.execute("update orderdetail set mark=5,WarehouseTime='"&now()&"' where id in ("&checkbox&")")
		
	elseif request.Form("button")="已创建包裹的商品" then
		conn.execute("update orderdetail set mark=6,PackageTime='"&now()&"' where id in ("&checkbox&")")
		
	elseif request.Form("button")="日本已寄出商品商品" then
		conn.execute("update orderdetail set mark=7 where id in ("&checkbox&")")	
	
	elseif request.Form("button")="已签收的商品" then
		conn.execute("update orderdetail set mark=8 where id in ("&checkbox&")")
	
	end if
	response.Redirect "Warehousing.asp?mark="&request("mark")&"&page="&request.QueryString("page")&""
end if
%>